#include "guiol.h"
#include "ui_guiol.h"

GuiOL::GuiOL(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GuiOL)
{
    ui->setupUi(this);
    connect(this->ui->listeAnime,SIGNAL(itemSelectionChanged()),this,SLOT(selectionChanged()));
    connect(this,SIGNAL(clearListeLiens()),this->ui->listeLiens,SLOT(clear()));

}

GuiOL::~GuiOL()
{
    delete ui;
}


void GuiOL::recevoirListeAnime(Anime * anime){

        this->ui->listeAnime->addItem(anime);

}

void GuiOL::selectionChanged(){
    QListWidgetItem *item = this->ui->listeAnime->currentItem();
    Anime *anime = (Anime*)item;
    if(!anime->getLoad()){
        anime->load();
    }
    this->ui->titreAnime->setText(anime->getTitre());
    this->ui->ImageAnime->setPixmap(QPixmap(QDir::currentPath()+"/data/img/"+anime->getImage()));
    this->ui->Synopsis->setText(anime->getDescription());
    while(this->ui->listeLiens->count() != 0) this->ui->listeLiens->takeItem(0);
    for(QVector<Episode>::Iterator it = anime->getEpisodes().begin(); it != anime->getEpisodes().end();it++)
        this->ui->listeLiens->addItem(it);

     for(QVector<Episode>::Iterator it = anime->getBonus().begin(); it != anime->getBonus().end();it++)
         this->ui->listeLiens->addItem(it);
    //Boucle des épisodes

}

